package version2024.medium;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author sunhl
 * @Description: HJ74 参数解析   字符串, 模拟
 * @Date: created in 2025/1/7 星期二 14:17
 * @Modified By:
 */
public class HJ74_ParameterAnalysis {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String nextLine = in.nextLine();

            // 保存一个单元的字符串
            StringBuilder sb = new StringBuilder();
            List<String> list = new ArrayList<>();
            // 标志位: 是否为起始的", 遇到起始"变为true, 遇到结束"变为false
            boolean quotation = false;

            for (int i = 0; i < nextLine.length(); i++) {
                // 遍历字符串
                char c = nextLine.charAt(i);

                // 识别", 遇到起始"变为true, 遇到结束"变为false
                if (String.valueOf(c).equals("\"")) {
                    quotation = !quotation;
                    // 退出当前循环, 终止信号很重要
                    continue;
                }

                // 识别空格, 若在"" 范围内, 不截断字符串, 范围外则进行截断
                if (String.valueOf(c).equals(" ") && !quotation) {
                    list.add(sb.toString());
                    sb = new StringBuilder();
                } else {
                    sb.append(c);
                }
            }

            list.add(sb.toString());

            System.out.println(list.size());
            for (String s : list) {
                System.out.println(s);
            }
        }
    }
}
